<?php
class xl_online_support{
    function read_list(){
        global $dbh;
        $sql='SELECT * FROM online_support ORDER BY id DESC';
        $sth=$dbh->prepare($sql);
        $sth->execute();
        return $sth->fetchAll();
    }
    function read_id($id){
        global $dbh;
        $sql='SELECT * FROM online_support WHERE id=:id LIMIT 0,1';
        $sth=$dbh->prepare($sql);
        $sth->execute(array(':id'=>$id));
        return $sth->fetch(PDO::FETCH_ASSOC);
    }
    function insert($data){
        global $dbh;
        $sql='INSERT INTO online_support (name,phone,fax,email,location,status,highlights) VALUE (:name,:phone,:fax,:email,:location,:status,:highlights)';
        $sth=$dbh->prepare($sql);
        $sth->execute($data);
        return $sth;
    }
    function delete_all($id){
        global $dbh;
        $sql='SELECT * FROM online_support WHERE id=:id';
        $sth=$dbh->prepare($sql);
        $sth->execute(array(':id'=>$id));
        return $sth->fetch(PDO::FETCH_ASSOC);
    }
    function delete($id){
        global $dbh;
        $sql='DELETE FROM online_support WHERE id=:id';
        $sth=$dbh->prepare($sql);
        $sth->execute(array(':id'=>$id));
        return $sth;
    }
    function update_highlights($id){
        global $dbh;
        $sql='UPDATE online_support SET highlights=1-highlights WHERE id=:id';
        $sth=$dbh->prepare($sql);
        $sth->execute(array(':id'=>$id));
        return $sth;
    }
    function update($data){
        global $dbh;
        $sql='UPDATE online_support SET name=:name,phone=:phone,fax=:fax,email=:email,location=:location,status=:status,highlights=:highlights WHERE id=:id';
        $sth=$dbh->prepare($sql);
        $sth->execute($data);
        return $sth;
    }
     function test_name($name){
        global $dbh;
        $sql='SELECT name FROM online_support WHERE name=:name';
        $sth=$dbh->prepare($sql);
        $sth->execute(array(':name'=>$name));
        return $sth->fetch(PDO::FETCH_ASSOC);
    }
    function test($id,$name){
        global $dbh;
        $sql='SELECT id,name FROM online_support WHERE id!=:id AND name=:name';
        $sth=$dbh->prepare($sql);
        $sth->execute(array(':id'=>$id,':name'=>$name));
        return $sth->fetchAll(PDO::FETCH_ASSOC);
    }
}